﻿using DevExpress.XtraEditors;
using SX_MesProject.Dtos;
using SX_MesProject.Dtos.ZFYDto;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;

using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static SX_MesProject.HttpClientHelper;

namespace SX_MesProject
{
    public partial class Login : DevExpress.XtraEditors.XtraForm
    {
        public Login()
        {
            InitializeComponent();
        }

        private void labelControl1_Click(object sender, EventArgs e)
        {

        }

        private void checkButton1_CheckedChanged(object sender, EventArgs e)
        {
#pragma warning disable CS4014 // 由于此调用不会等待，因此在调用完成前将继续执行当前方法
            DataButton();
#pragma warning restore CS4014 // 由于此调用不会等待，因此在调用完成前将继续执行当前方法
        }
        public async Task DataButton()
        {

            LoginDto login = new LoginDto();
            login.name = this.userName.Text;
            login.pwd = this.pwd.Text;
            var res = await HttpClientHelper.RequestUrl<LoginDto, ApiResult<UserDto>>("https://localhost:44556/", "Login/LoginUser", MethodType.POST, login);
            if (res.Code == 200)
            {
                MessageBox.Show("登录成功");
                Form1 main = new Form1();
                main.Show();
                this.Hide();
            }
            else
            {
                XtraMessageBox.Show("用户名或密码错误！");
            }
        }

        private void pwd_EditValueChanged(object sender, EventArgs e)
        {

        }
    }
}